import { getReadyProduct } from '../core/ReadyProducts'
import { currentTime } from '../core/SimulationClock'
import { messageTransfer } from '../messaging/MessageTransfer'
import BaseStation from './BaseStation'
import Product from './Product'

class Sink extends BaseStation {
  receivedCount = 0

  constructor(id: string, name: string, x: number, y: number, width = 100, height = 100) {
    super(id, name, x, y, width, height)
  }

  //是否可以接受产品
  canReceiveProduct(): boolean {
    return true
  }

  // 接受就绪产品
  receiveReadyProduct(productId: string): void {
    this.receiveProduct(productId)
  }

  receiveProduct(productId: string): void {
    const product = getReadyProduct(productId)
    if (product) {
      messageTransfer('product', 'move', { targetId: this.id, productId: product.id })
      this.receivedCount++
      console.log(`[${currentTime}] ✅ ${product.id} 已被 ${this.name} 吸收`)
      messageTransfer('product', 'recycle', { targetId: this.id, productId: product.id })
    } else {
      console.log(`[${currentTime}] ❌ ${productId} 没有发现`)
    }
  }

  public onProductReceived(product: Product): void {
    return
  }

  public tryDispatchCurrentProduct(): void {
    return
  }
}

export default Sink
